let a = sessionStorage.getItem("token");
let b = sessionStorage.getItem("b");

let imgBox = document.querySelector(".imgBox");
let saveBtn = document.querySelector(".saveBtn");
let name = document.querySelector(".name");
let dataP = document.querySelector(".dataP");
let p;
let n=sessionStorage.getItem("n");




let api = "http://newshopapi.0melon0.cn/api/f_user/bookday";
let method = "POST";
let data = {
    "token": a,
    "day_time": b,
    "show_id": 2
};
ajax(method, api, function (res) {
    console.log(res);
    p = res.result.id;
    dataP.innerHTML = `${res.result.day_time}`;  //渲染时间

    //渲染名字
    name.innerHTML = `
    <p>${n}</p>     

`;

    let api = `http://newshopapi.0melon0.cn/api/f_user/Qrcode?token=${a}&id=${p}`;
    let method = "GET";
    ajax(method, api, data => {
        imgBox.innerHTML = `
    <img src="${data.data.data}" id="testImg" alt="">
            
            `;
        saveBtn.addEventListener("click", function () {
            var img = document.getElementById('testImg'); // 获取要下载的图片
            var url = img.src;                            // 获取图片地址
            var a = document.createElement('a');          // 创建一个a节点插入的document
            var event = new MouseEvent('click')           // 模拟鼠标click点击事件
            a.download = '图片名字'                  // 设置a节点的download属性值
            a.href = url;                                 // 将图片的src赋值给a节点的href
            a.dispatchEvent(event);

            setTimeout(function () {
                window.location.href = "./mine.html"
            }, 2000)

        });
    })

}, data)


